// 路由
import {
	RouterMount,
	createRouter
} from './uni-simple-router.js'
import store from '@/store'
const whitelist = {     //声明了一个白名单
	'/pages/tabbar/tabbar-1/tabbar-1': '/',
}
const router = createRouter({
	platform: "wechat",
	applet: {
		animationDuration: 0 //默认 300ms
	},
	routerErrorEach: ({
		type,
		msg
	}) => {
		switch (type) {
			case 3: // APP退出应用
				// #ifdef APP-PLUS
				router.$lockStatus = false;
				uni.showModal({
					title: '提示',
					content: '您确定要退出应用吗？',
					success: function(res) {
						if (res.confirm) {
							plus.runtime.quit();
						}
					}
				});
				// #endif
				break;
			case 2:
			case 0:
				router.$lockStatus = false;
				break;
			default:
				break;
		}

	},
	// 通配符，非定义页面，跳转404
	routes: [
		...ROUTES,
		{
			path: '*',
			redirect: (to) => {
                return {name:'404'}
			}
		},
	]
});
//全局路由前置守卫
router.beforeEach((to, from, next) => {
console.log("==============router1111",!store.getters.token,)
	// 权限控制登录
	console.log("======location",!store.getters.token&&window.location.href.indexOf('#'))
    if (!store.getters.token&&window.location.href.indexOf('#')) {
		let arr = window.location.href.split('#')
		let path = '/#'+arr[1]
		console.log("======location",path)
		store.dispatch("getUserInfoAll",{path:path})
    } else {
        next()
    }
});
router.afterEach((to, from) => {
	// 通过config接口注入权限验证配置，我封装在了 vuex 里
	//store.dispatch("handleWxConfig");
  });

export {
	router,
	RouterMount
}
